<template>
  <div class="divBox">
    <el-card class="box-card">
      <el-form inline size="small" @submit.native.prevent>
        <el-form-item label="关键词：">
          <el-input v-model="listPram.keyword" placeholder="关键词" clearable class="selWidth"/>
        </el-form-item>
        <el-form-item label="地区:" prop="areaId">
          <el-cascader class="col"
                       placeholder="可输入地区名称进行搜索"
                       v-model="value"
                       :options="options"
                       clearable
                       :props="{ expandTrigger: 'hover' }"
                       filterable
                       @change="handleChange"></el-cascader>
        </el-form-item>
        <el-form-item>
          <el-button icon="el-icon-search" size="mini" type="primary" @click.native="getList">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-form>
      <el-table :data="listData.list" size="mini" :header-cell-style=" {fontWeight:'bold',background:'#f8f8f9',color: '#515a6e',height:'40px'}" border>
        <el-table-column label="ID" prop="id" width="40" ></el-table-column>
        <el-table-column label="头像" prop="avatar" width="80">
          <template slot-scope="scope">
            <el-image :src="scope.row.avatar"></el-image>
          </template>
        </el-table-column>
        <el-table-column label="昵称" prop="name" width="120">
          <template slot-scope="scope">
            <div> {{scope.row.name||'-'}}</div>
          </template>
        </el-table-column>
        <el-table-column label="手机号" prop="phone" width="100"/>
        <el-table-column label="所在地区" prop="areaText" width="250"/>
        <el-table-column label="益联券" prop="voucher" width="80"/>
        <el-table-column label="积分" prop="integral" width="80"/>
        <el-table-column label="是否商家"  width="80" prop="status">
          <template slot-scope="scope">
            <div style="color:#1224ee;" v-if="scope.row.status===1">否</div>
            <div style="color:#15f50d;" v-if="scope.row.status===2">是</div>
          </template>
        </el-table-column>
        <el-table-column label="操作" min-width="160" fixed="right" align="center">
          <template slot-scope="scope">
            <el-button icon="el-icon-edit" size="mini" type="primary" @click="openEdit(scope.row.id)"  v-has-permi="['admin:user:detail']">更改客服</el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
          :current-page="listPram.page"
          :page-sizes="[20,40,60,80,100]"
          layout="total, sizes, prev, pager, next, jumper"
          :total="listData.count"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
      />
    </el-card>
    <el-dialog
        :visible.sync="editDialog.show"
        title="选择客服"
        destroy-on-close
        :close-on-click-modal="false"
        width="1200px"
        append-to-body>
      <edit
          v-if="editDialog.show"
          :businessId="editDialog.id"
          :customerId="this.id"
          @hideEditDialog="hideEditDialog"
          ref="editForm"
      />
    </el-dialog>
  </div>
</template>

<script>
import {deleteRow, vipList} from "@/api/exclusiveService";
import {checkPermi} from "@/utils/permission";
import {optionsList} from "@/api/business";
import Edit from "@/views/operate/exclusiveService/jurisdiction/edit.vue";
export default {
  components: {Edit},
  props: {
    id: {
      default: null
    }
  },
  data() {
    return {
      listData: { list: [],count:0 },
      listPram: {
        keyword: '',
        areaId:'',
        page: 1,
        limit: 20,
        id:''
      },
      editDialog:{
        show:false,
        id:null
      },
      userGrant: {
        show: false,
        id: null,
        editDate: {},
        pid: null
      },
      tableLoading:false,
      value: [],
      options: [{
        value: '',
        label: '',
        children: [{
          value: '',
          label: '',
          children: [{
            value: '',
            label: ''
          }]
        }]
      }],
    }
  },
  mounted() {
    this.getList()
    this.getOptions()
  },
  methods: {
    handleChange(value) {
      this.listPram.areaId = value[2]
    },
    getOptions() {
      optionsList().then(res => {
        this.options = res
      })
    },
    checkPermi,
    getList(){
      this.tableLoading=true
      this.listPram.id = this.id
      vipList(this.listPram).then(res=>{
        this.listData.list=res.list;
        this.listData.count=res.count;
      }).finally(()=>{})
      this.tableLoading=false;
    },
    openEdit(id=null){
      this.editDialog.id=id;
      this.editDialog.show=true
    },
    openUserGrant(id = null, editDate) {
      this.userGrant.id = id;
      this.userGrant.show = true
      this.userGrant.editDate = editDate
    },
    handlerDelete(id) {
      this.$confirm('确认删除该数据吗？').then(() => {
        const loading=this.$loading({text:'删除中',background:'rgba(255,255,255,.5)'})
        deleteRow(id).then(() => {
          this.$message.success('删除成功')
          this.getList()
        }).finally(()=>{
          loading.close()
        })
      })
    },
    hideEditDialog() {
      this.editDialog.show = false
      this.getList()
    },
    hideUserGrantDialog() {
      this.userGrant.show = false
      this.getList()
    },
    handleSizeChange(val) {
      this.listPram.limit = val
      this.getList()
    },
    handleCurrentChange(val) {
      this.listPram.page = val
      this.getList()
    },
    resetQuery(){
      this.listPram.keyword = '';
      this.listPram.areaId = '';
      this.value = ''
      this.getList()
    }
  }
}
</script>

<style scoped lang="scss">

</style>
